<?php
// 我们的服务信息
class DomainAction extends Action {
	/**
	 *
	 *
	 * 判断域名是否已经注册 (会返回 coderbolg.com/coderbolg.net的注册情况)
	 *
	 * @param
	 *        	$domain
	 *        	
	 * @param
	 *        	$ext
	 *        	
	 * @return ARRAY
	 *
	 * @author zhuwc
	 *        
	 * @version (2011-09-09)
	 *         
	 *         
	 *         
	 */
	function test2(){
		set_time_limit(0);
		$this->isRegister('aa');
	}
	function test3(){
		preg_match("|<div class="lyTableInfoWrap">(. ?)</div>|is", @file_get_contents(        http://www.xinnet.cn/Modules/agent/serv/pages/domain_whois.jsp?domainNameWhois=.$domain.&noCode=noCode), $whois);
		dump( $whois[0]);
	}
	function test(){
		set_time_limit(0);
		$time = time();
		
		$id = $_GET ['id'] ? $_GET ['id'] : 0;
		$map ['id'] = array (
				'exp',
				'>' . $id
		);
		$map['status'] = array('exp','=0');
		$list = M('domain')->where($map)->order ( 'id asc' )->limit(1)->select();
		//dump($list);exit;
		if(empty($list)){
			dump('over');
			exit;
		}
		
		foreach ($list as $vo){
			$domain = $vo['domain'].'.com';
			$t = time();
			$save['status'] = $this->isRegister($domain);
			dump('*******************');
			dump(time()-$t);
			$where['id'] =$id = $vo['id'];
			M('domain')->where($where)->save($save);
			dump($domain.'====='.$save['status']);
		}
		
		dump(time()-$time);
		$time = time();
		
		//dump($id);
		//exit;
		echo "<script type='text/javascript'>window.location.href='http://192.168.1.106/about/test/id/".$id."';</script>";
		
	}
	function isRegister($domain, $ext = array('com')) {
		if (empty ( $domain )) {
			return false;
		}
		
		$post_data = $curl = $text = $return = array ();
		foreach ( $ext as $v ) {
			$post_data [] = array (
					'domain' => $domain . '.' . $v 
			);
		}
		
		$urls = array_fill ( 0, count ( $post_data ), 
		'http://pandavip.www.net.cn/check/check_ac1.cgi' );
		$handle = curl_multi_init ();
		foreach ( $urls as $k => $v ) {
			$curl [$k] = curl_init ( $v );
			curl_setopt ( $curl [$k], CURLOPT_HTTPHEADER, array (
					"User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2",
					"Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
					"Accept-Language: zh-cn,zh;q=0.5" 
			)
			 );
			
			curl_setopt ( $curl [$k], CURLOPT_REFERER, 'http://www.net.cn/' );
			curl_setopt ( $curl [$k], CURLOPT_RETURNTRANSFER, 1 );
			curl_setopt ( $curl [$k], CURLOPT_POST, 1 );
			curl_setopt ( $curl [$k], CURLOPT_POSTFIELDS, $post_data [$k] );
			curl_multi_add_handle ( $handle, $curl [$k] );
		}
		
		$active = null;
		
		do {
			$mrc = curl_multi_exec ( $handle, $active );
		} while ( $mrc == CURLM_CALL_MULTI_PERFORM );
		
		while ( $active && $mrc == CURLM_OK ) {
			if (curl_multi_select ( $handle ) != - 1) {
				do {
					$mrc = curl_multi_exec ( $handle, $active );
				} while ( $mrc == CURLM_CALL_MULTI_PERFORM );
			}
		}
		
		foreach ( $curl as $k => $v ) {
			if (curl_error ( $curl [$k] ) == "") {
				$text [$k] = ( string ) curl_multi_getcontent ( $curl [$k] );
			}
			
			curl_multi_remove_handle ( $handle, $curl [$k] );
			curl_close ( $curl [$k] );
		}
		
		curl_multi_close ( $handle );
		
		foreach ( $text as $key => $value ) {
			if (false === $pos = strrpos ( $value, '|' )) {
				$return [$key] = $ext [$key] . '|False';
			} else {
				if (false === strrpos ( substr ( $value, $pos ), 'not' )) {
					$return [$key] = $ext [$key] . '|Unregistered';
				} else {
					$return [$key] = $ext [$key] . '|Registered';
				}
			}
		}
		
		return $return;
	}
}
?>